import Vue from 'vue'
import VueRouter from 'vue-router'
// eslint-disable-next-line no-unused-vars
import prdcount from '@/components/prdcount.vue'
import asset from '@/components/asset.vue'
import earn from '@/components/earn.vue'
import chengben from '@/components/chengben.vue'
import totalyingli from '@/components/totalyingli.vue'
import Navi from '@/components//Navi/Navi.vue'
import Login from '@/components/login/Login'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [{
    path: '/',
    // name:'home',
    component: Navi,
    children: [
      {
        path: 'prdcount',
        name: 'Navi',
        component: resolve => require(['@/components/prdcount'], resolve)
      },
      {
        path: 'asset',
        name: 'Navi',
        component: asset
      },
      {
        path: 'earn',
        name: 'Navi',
        component: earn
      },
      {
        path: 'chengben',
        name: 'Navi',
        component: chengben
      },
      {
        path: 'totalyingli',
        name: 'Navi',
        component: totalyingli
      }
    ]
  },

  {
    path: '/Navi',
    component: Navi
  },
  {
    path: '/Login',
    component: Login
  }
  ]
})

export default router

// 添加路由守卫
router.beforeEach((to, from, next) => {
  const isLogin = !!sessionStorage.eleToken
  if (to.path === '/Login') {
    next()
  } else {
    isLogin ? next() : next('/Login')
  }
})
